<template>
  <div class="layout-route">
      <div class="card card-search">
          <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
              <el-form-item label="店铺" prop="shop_id">
                  <el-select v-model="queryParams.shop_id" placeholder="请选择店铺" clearable size="small" style="width: 240px">
                      <el-option v-for="(dict, index) in shopList" :key="index" :label="dict.shop_name" :value="dict.shop_id" />
                  </el-select>
              </el-form-item>
               <el-form-item label=" ">
                  <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
          </el-form>
      </div>

      <div class="card">
          <el-row :gutter="10" class="mb8">
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>
          <el-table v-loading="loading" :data="tableData" border script>
              <el-table-column label="店铺名称" prop="shop_name" min-width="240" show-overflow-tooltip></el-table-column>
              <el-table-column label="邮箱" prop="email" min-width="200" show-overflow-tooltip></el-table-column>
              <el-table-column label="地址" prop="myshopify_domain" min-width="240" show-overflow-tooltip></el-table-column>
              <el-table-column label="状态" prop="status" min-width="100">
                  <template slot-scope="scope">
                      {{ scope.row.status | formatLabelByValueFuzzy(STATUS_LIST) }}
                  </template>
              </el-table-column>
              <el-table-column label="站点" prop="site" min-width="100">
                  <template slot-scope="scope">
                      <el-tag type="info">{{ scope.row.site }}</el-tag>
                  </template>
              </el-table-column>
              <el-table-column label="创建时间" prop="created_time" min-width="160"></el-table-column>
              <el-table-column label="操作" min-width="120" fixed="right">
                  <template slot-scope="scope">
                      <el-button type="text" icon="el-icon-edit" @click="showDetailDialog(scope.row)">编辑</el-button>
                  </template>
              </el-table-column>
          </el-table>
          <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList"></pagination>
      </div>
      <detail-dialog v-model="detailDialog.visible" v-if="detailDialog.visible" :params="detailDialog.data" @success="handleQuery"></detail-dialog>
  </div>
</template>

<script>
import { queryShopList, getShopList } from '@/api/shop'
// import { STATUS_LIST } from '../constant'
// import DetailDialog from '../components/DetailDialog.vue'
export default {
  name: 'StockList',
  // components: { DetailDialog },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 显示搜索条件
          showSearch: true,
          // 总条数
          total: 0,
          // 表格数据
          tableData: [],
          // 店铺列表下拉
          shopList: [],
          STATUS_LIST,
          pageInfo: {
              page: 1,
              limit: 10,
          },
          // 查询参数
          queryParams: {
              shop_id: undefined,
          },
          detailDialog: {
              visible: false,
              data: {}
          }
      }
  },
  async created() {
      this.loading = true
      try {
          const result = await getShopList()
          this.shopList = result?.data?.list ?? []
      } catch (error) {
          this.loading = false
          console.log(error)
      }
      this.getList()
  },
  methods: {
      showDetailDialog(row) {
          this.detailDialog.visible = true
          this.detailDialog.data = row
      },
      //列表
      getList() {
          this.loading = true
          const qyparams = {
              ...this.pageInfo,
              ...this.queryParams,
          }
          queryShopList(qyparams)
              .then(response => {
                  this.tableData = response.data.list
                  this.total = response.data.total
              })
              .finally(() => {
                  this.loading = false
              })
      },

      // 搜索按钮操作
      handleQuery() {
          this.pageInfo.page = 1
          this.getList()
      },

      // 重置按钮操作
      resetQuery() {
          this.resetForm('queryForm')

          this.handleQuery()
      },
  },
}
</script>
